<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">






  
  
  <link rel="stylesheet" media="all" href="/blog/lib/Han/dist/han.min.css?v=3.3">




<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="读书笔记,算法学习," />








  <link rel="shortcut icon" type="image/x-icon" href="/blog/favicon.ico?v=5.1.2" />






<meta name="description" content="岩雀滑行时间限制: 1 Sec  内存限制: 128 MB 岩雀塔里娅喜欢在瓦洛兰的大山里练习滑行。练习场是一个方阵，塔里娅可以滑向上下左右相邻四个点中高度减小的点。为了追求更好的滑行体验，塔里娅想知道一条经过格子数目最多的滑行方案。 输入输入的第一行表示区域的行数R和列数C(1 &amp;lt;= R,C &amp;lt;= 500)。下面是R行，每行有C个整数（空格分隔），代表点的高度h，0&amp;lt;=h&amp;lt">
<meta name="keywords" content="读书笔记,算法学习">
<meta property="og:type" content="article">
<meta property="og:title" content="岩雀滑行">
<meta property="og:url" content="https://git.oschina.net/choichumgming/blog/2017/09/29/岩雀滑行/index.html">
<meta property="og:site_name" content="choichumgming&#39;s blog">
<meta property="og:description" content="岩雀滑行时间限制: 1 Sec  内存限制: 128 MB 岩雀塔里娅喜欢在瓦洛兰的大山里练习滑行。练习场是一个方阵，塔里娅可以滑向上下左右相邻四个点中高度减小的点。为了追求更好的滑行体验，塔里娅想知道一条经过格子数目最多的滑行方案。 输入输入的第一行表示区域的行数R和列数C(1 &amp;lt;= R,C &amp;lt;= 500)。下面是R行，每行有C个整数（空格分隔），代表点的高度h，0&amp;lt;=h&amp;lt">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-12-26T08:36:16.823Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="岩雀滑行">
<meta name="twitter:description" content="岩雀滑行时间限制: 1 Sec  内存限制: 128 MB 岩雀塔里娅喜欢在瓦洛兰的大山里练习滑行。练习场是一个方阵，塔里娅可以滑向上下左右相邻四个点中高度减小的点。为了追求更好的滑行体验，塔里娅想知道一条经过格子数目最多的滑行方案。 输入输入的第一行表示区域的行数R和列数C(1 &amp;lt;= R,C &amp;lt;= 500)。下面是R行，每行有C个整数（空格分隔），代表点的高度h，0&amp;lt;=h&amp;lt">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Gemini',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://git.oschina.net/choichumgming/blog/2017/09/29/岩雀滑行/"/>





  <title>岩雀滑行 | choichumgming's blog</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">choichumgming's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">stay foolish,stay hard</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/blog/404.html" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br />
            
            公益404
          </a>
        </li>
      
        
        <li class="menu-item menu-item-board">
          <a href="/blog/board/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-book"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://git.oschina.net/choichumgming/blog/blog/2017/09/29/岩雀滑行/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="choichumgming">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="choichumgming's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">岩雀滑行</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-29T20:44:12+08:00">
                2017-09-29
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/算法与数据结构/" itemprop="url" rel="index">
                    <span itemprop="name">算法与数据结构</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-comment-o"></i>
              </span>
              
                <a href="/blog/2017/09/29/岩雀滑行/#SOHUCS" itemprop="discussionUrl">
                  <span id="changyan_count_unit" class="post-comments-count hc-comment-count" data-xid="2017/09/29/岩雀滑行/" itemprop="commentsCount"></span>
                </a>
              
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body han-init-context" itemprop="articleBody">

      
      

      
        <p><strong>岩雀滑行</strong><br>时间限制: 1 Sec  内存限制: 128 MB</p>
<p>岩雀塔里娅喜欢在瓦洛兰的大山里练习滑行。练习场是一个方阵，塔里娅可以滑向上下左右相邻四个点中高度减小的点。为了追求更好的滑行体验，塔里娅想知道一条经过格子数目最多的滑行方案。</p>
<p><strong>输入</strong><br>输入的第一行表示区域的行数R和列数C(1 &lt;= R,C &lt;= 500)。下面是R行，每行有C个整数（空格分隔），代表点的高度h，0&lt;=h&lt;=10000。</p>
<p><strong>输出</strong><br>输出最长方案的长度（经过格子数目）。</p>
<p><strong>样例输入</strong><br>5 5<br>1 2 3 4 5<br>16 17 18 19 6<br>15 24 30 20 7<br>14 23 22 21 8<br>13 12 11 10 9<br><strong>样例输出</strong><br>25</p>
<p>&nbsp;&nbsp;这题目折腾一个星期终于搞懂了。<br>&nbsp;&nbsp;第三种方法在网上看到很多说用dp的，但是都没怎么具体说如何dp，以及这道题dp的含义。该题其实就是将最长下降子序列由线变成平面，每个点的数量状态是由它的相邻点中小于它的点的数量状态所决定的。<br>&nbsp;&nbsp;将平面内的高度全部按顺序排列成线型，然后存入一个一维数组（<strong>当然这个点的坐标也要和高度一起放入数组里面，因为在后面会用到</strong>）。<br>可以从高到低排的，也可以从低到高。<br>&nbsp;&nbsp;如果从低往高排，当遍历这个一维数组时，每次都要将当前点的高度与周围高度相比较，再从周围比自己高度高的点中的，选当前步数最多的点，放入自己的dp中，然后就这样dp到末尾。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div></pre></td><td class="code"><pre><div class="line">import java.util.ArrayList;</div><div class="line">import java.util.Scanner;</div><div class="line"></div><div class="line">/*</div><div class="line"> * 使用dfs</div><div class="line"> * 该方法超时</div><div class="line"> */</div><div class="line">public class Oj1303岩雀滑行 &#123;</div><div class="line">	int [][]mark;//存着到达当前位置的最长步数值</div><div class="line">	int [][]map;//存h</div><div class="line">	int r,c=0;</div><div class="line">	int maxstep;//最大步数</div><div class="line">	int tx[]=&#123;0,0,-1,1&#125;,ty[]=&#123;1,-1,0,0&#125;;</div><div class="line">	ArrayList&lt;Node&gt; que;</div><div class="line"></div><div class="line">	public Oj1303岩雀滑行() &#123;</div><div class="line">		Scanner sc=new Scanner(System.in);</div><div class="line">		r=sc.nextInt();c=sc.nextInt();</div><div class="line">		map=new int[r+1][c+1]; mark=new int[r+1][c+1];</div><div class="line">		que=new ArrayList&lt;Node&gt;();</div><div class="line"></div><div class="line">		for(int i=0;i&lt;r;i++)</div><div class="line">			for(int j=0;j&lt;c;j++)</div><div class="line">			&#123;</div><div class="line">				map[i][j]=sc.nextInt();</div><div class="line">				mark[i][j]=0;</div><div class="line">				Node t=new Node(i, j, 1); //一开始将每个节点放入队列，因为不知道从哪个节点开始能走到最长的步数</div><div class="line">				que.add(t);</div><div class="line">			&#125;</div><div class="line">		search();</div><div class="line">		System.out.println(maxstep);</div><div class="line">	&#125;</div><div class="line">	private void search() &#123;</div><div class="line">		// TODO Auto-generated method stub</div><div class="line">			int head=0;</div><div class="line"></div><div class="line">			while(head&lt;que.size())&#123;</div><div class="line"></div><div class="line">				Node temp=que.get(head);</div><div class="line">				head++;</div><div class="line">				for(int i=0;i&lt;4;i++)&#123;</div><div class="line">					int x=temp.x+tx[i];int y=temp.y+ty[i];</div><div class="line">					int nx=temp.x;int ny=temp.y;</div><div class="line"></div><div class="line">					if(x&gt;=0 &amp;&amp;x&lt;r &amp;&amp;y&gt;=0 &amp;&amp; y&lt;c)&#123;</div><div class="line">						if(map[x][y]&lt;map[nx][ny] &amp;&amp; mark[x][y]&lt;(temp.step+1))&#123;//如果走到当前位置时的步数能大于当前位置的最大步数值，就更新该位置的步数，并重新创建节点放入走过该节点的最大值</div><div class="line">							Node newNode=new Node(x,y,temp.step+1);</div><div class="line">							mark[x][y]=(temp.step+1);</div><div class="line">							maxstep=mark[x][y]&gt;maxstep?mark[x][y]:maxstep;//每次放入队列前都和最大步数比较一下</div><div class="line">							que.add(newNode);</div><div class="line">						&#125;</div><div class="line">					&#125;</div><div class="line">				&#125;</div><div class="line"></div><div class="line">			&#125;</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	class Node&#123;</div><div class="line">		int x;</div><div class="line">		int y;</div><div class="line">		int step;</div><div class="line">		public Node(int x, int y, int step) &#123;</div><div class="line">			super();</div><div class="line">			this.x = x;</div><div class="line">			this.y = y;</div><div class="line">			this.step = step;</div><div class="line">		&#125;</div><div class="line"></div><div class="line">	&#125;</div><div class="line"></div><div class="line"></div><div class="line">	public static void main(String[] args) &#123;</div><div class="line">		// TODO Auto-generated method stub</div><div class="line">		Oj1303岩雀滑行 P=new Oj1303岩雀滑行();</div><div class="line">	&#125;</div><div class="line"></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div></pre></td><td class="code"><pre><div class="line">import java.util.ArrayList;</div><div class="line">import java.util.Scanner;</div><div class="line"></div><div class="line">/*</div><div class="line"> * 使用bfs</div><div class="line"> * 该方法超时</div><div class="line"> */</div><div class="line">public class Oj1303岩雀滑行2 &#123;</div><div class="line">	int [][]mark;//存着到达当前位置的最长步数值</div><div class="line">	int [][]map;//存h</div><div class="line">	int r,c=0;</div><div class="line">	int maxstep;//最大步数</div><div class="line">	int tx[]=&#123;0,0,-1,1&#125;,ty[]=&#123;1,-1,0,0&#125;;</div><div class="line">	ArrayList&lt;Node&gt; que;</div><div class="line"></div><div class="line">	public Oj1303岩雀滑行2() &#123;</div><div class="line">		Scanner sc=new Scanner(System.in);</div><div class="line">		r=sc.nextInt();c=sc.nextInt();</div><div class="line">		map=new int[r+1][c+1]; mark=new int[r+1][c+1];</div><div class="line">		que=new ArrayList&lt;Node&gt;();</div><div class="line">		int max=0;</div><div class="line">		for(int i=0;i&lt;r;i++)</div><div class="line">			for(int j=0;j&lt;c;j++)</div><div class="line">			&#123;</div><div class="line">				map[i][j]=sc.nextInt();</div><div class="line">				mark[i][j]=1;</div><div class="line">			&#125;</div><div class="line">		maxstep=search(0,0);</div><div class="line">		System.out.println(maxstep);</div><div class="line">	&#125;</div><div class="line">	private int search(int x,int y) &#123;</div><div class="line">		if(mark[x][y]&gt;1) return mark[x][y];</div><div class="line">		int max=0;</div><div class="line">		for(int i=0;i&lt;4;i++)&#123;</div><div class="line">			int px=x+tx[i];int py=y+ty[i];</div><div class="line">			if(px&gt;=0 &amp;&amp;px&lt;r &amp;&amp;py&gt;=0 &amp;&amp; py&lt;c)&#123;</div><div class="line">				if(map[x][y]&lt;map[px][py])&#123;</div><div class="line"></div><div class="line">					max=max&gt;search(px,py)?max:search(px,py);</div><div class="line">				&#125;</div><div class="line">			&#125;</div><div class="line">		&#125;</div><div class="line">		mark[x][y] = max + 1;</div><div class="line">		return max+1;</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	class Node&#123;</div><div class="line">		int x;</div><div class="line">		int y;</div><div class="line">		int step;</div><div class="line">		public Node(int x, int y, int step) &#123;</div><div class="line">			super();</div><div class="line">			this.x = x;</div><div class="line">			this.y = y;</div><div class="line">			this.step = step;</div><div class="line">		&#125;</div><div class="line"></div><div class="line">	&#125;</div><div class="line"></div><div class="line"></div><div class="line">	public static void main(String[] args) &#123;</div><div class="line">		// TODO Auto-generated method stub</div><div class="line">		Oj1303岩雀滑行2 P=new Oj1303岩雀滑行2();</div><div class="line">	&#125;</div><div class="line"></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div></pre></td><td class="code"><pre><div class="line">import java.util.ArrayList;</div><div class="line">import java.util.Scanner;</div><div class="line"></div><div class="line">/*</div><div class="line"> * dp动归</div><div class="line"> * 该题其实就是将最长下降子序列由线变成平面</div><div class="line"> * 每个点的数量状态是由它的相邻点中小于它的点的数量状态所决定的</div><div class="line"> *</div><div class="line"> */</div><div class="line">public class Oj1303岩雀滑行3 &#123;</div><div class="line"></div><div class="line">	int [][]map;//存h</div><div class="line">	Node []temp;//将二维化为一维，里面存放着高度和坐标值</div><div class="line">	int r,c=0;</div><div class="line">	int tx[]=&#123;0,0,-1,1&#125;,ty[]=&#123;1,-1,0,0&#125;;</div><div class="line">	int maxstep=0;</div><div class="line"></div><div class="line">	public Oj1303岩雀滑行3() &#123;</div><div class="line">		Scanner sc=new Scanner(System.in);</div><div class="line">		r=sc.nextInt();c=sc.nextInt();</div><div class="line">		map=new int[r+1][c+1];</div><div class="line"></div><div class="line">		temp=new Node[r*c+1];</div><div class="line">		int kp=0;</div><div class="line">		for(int i=0;i&lt;r;i++)</div><div class="line">			for(int j=0;j&lt;c;j++)&#123;</div><div class="line">				map[i][j]=sc.nextInt();</div><div class="line">				temp[kp]=new Node(map[i][j],i,j);</div><div class="line">				kp++;</div><div class="line">			&#125;</div><div class="line"></div><div class="line"></div><div class="line">		sort();</div><div class="line"></div><div class="line">		System.out.println(search());</div><div class="line"></div><div class="line">	&#125;</div><div class="line">	private void sort()&#123;//将降维的数组排序</div><div class="line">		for(int i=0;i&lt;r*c;i++)</div><div class="line">			for(int j=0;j&lt;r*c;j++)</div><div class="line">			&#123;</div><div class="line">				if(temp[i].data &lt;temp[j].data)&#123;</div><div class="line">					Node t=null;</div><div class="line">					t=temp[j];</div><div class="line">					temp[j] =temp[i];</div><div class="line">					temp[i]=t;</div><div class="line">				&#125;</div><div class="line"></div><div class="line">			&#125;</div><div class="line">	&#125;</div><div class="line">	private int search() &#123;</div><div class="line">		// TODO Auto-generated method stub</div><div class="line">		int [][]dp=new int[r+1][c+1];</div><div class="line">		int a,b,x,y,ans=0;</div><div class="line">	    for (int i=0;i&lt;r*c;i++)</div><div class="line">	    &#123;</div><div class="line">	        a=temp[i].x;b=temp[i].y;</div><div class="line">	        for (int j=0;j&lt;4;j++)</div><div class="line">	        &#123;</div><div class="line">	            x=a+tx[j];y=b+ty[j];</div><div class="line">	            if (x&gt;=0&amp;&amp;y&gt;=0 &amp;&amp; x&lt;r&amp;&amp;y&lt;c&amp;&amp;map[x][y]&lt;map[a][b])</div><div class="line">	                dp[a][b]=dp[x][y]&gt;dp[a][b]?dp[x][y]:dp[a][b];</div><div class="line">	        &#125;</div><div class="line">	        dp[a][b]++;</div><div class="line">	        ans=(ans&gt;dp[a][b])?ans:dp[a][b];</div><div class="line">	    &#125;</div><div class="line">	    return ans;</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	public class Node&#123;</div><div class="line">		int data=0;</div><div class="line">		int x;int y;</div><div class="line"></div><div class="line">		public Node(int data, int x, int y) &#123;</div><div class="line"></div><div class="line">			this.data = data;</div><div class="line">			this.x = x;</div><div class="line">			this.y = y;</div><div class="line">		&#125;</div><div class="line"></div><div class="line">	&#125;</div><div class="line">	public static void main(String[] args) &#123;</div><div class="line">		Oj1303岩雀滑行3 p=new Oj1303岩雀滑行3();</div><div class="line">	&#125;</div><div class="line"></div><div class="line"></div><div class="line">&#125;</div></pre></td></tr></table></figure>
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/读书笔记/" rel="tag"># 读书笔记</a>
          
            <a href="/blog/tags/算法学习/" rel="tag"># 算法学习</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2017/09/29/算法学习之动态规划（一）/" rel="next" title="动态规划（一）">
                <i class="fa fa-chevron-left"></i> 动态规划（一）
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2017/10/10/算法学习之动态规划（二）/" rel="prev" title="动态规划（二）">
                动态规划（二） <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <!--PC版-->
<div id="SOHUCS" ></div>


    

  </div>
     <div class="comments" id="comments">
       
     </div>
   





        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview sidebar-panel sidebar-panel-active">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/blog/images/avatar.gif"
               alt="choichumgming" />
          <p class="site-author-name" itemprop="name">choichumgming</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/blog/archives/">
                <span class="site-state-item-count">15</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/blog/categories/index.html">
                <span class="site-state-item-count">5</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              
                <span class="site-state-item-count">6</span>
                <span class="site-state-item-name">标签</span>
              
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="http://www.weibo.com/u/2558763801" target="_blank" title="微博">
                  
                    <i class="fa fa-fw fa-weibo"></i>
                  
                    
                      微博
                    
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">choichumgming</span>

  
</div>


  <div class="powered-by">
    由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
  </div>

  <span class="post-meta-divider">|</span>

  <div class="theme-info">
    主题 &mdash;
    <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
      NexT.Gemini
    </a>
  </div>


        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.2"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.2"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.2"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.2"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  




  
    <script type="text/javascript">
    (function(){
      var appid = 'cytnT5dky';
      var conf = '56c170b7352bd027682e3707e9eb5071';
      var width = window.innerWidth || document.documentElement.clientWidth;
      if (width < 960) {
      window.document.write('<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf + '"><\/script>'); } else { var loadJs=function(d,a){var c=document.getElementsByTagName("head")[0]||document.head||document.documentElement;var b=document.createElement("script");b.setAttribute("type","text/javascript");b.setAttribute("charset","UTF-8");b.setAttribute("src",d);if(typeof a==="function"){if(window.attachEvent){b.onreadystatechange=function(){var e=b.readyState;if(e==="loaded"||e==="complete"){b.onreadystatechange=null;a()}}}else{b.onload=a}}c.appendChild(b)};loadJs("https://changyan.sohu.com/upload/changyan.js",function(){
        window.changyan.api.config({appid:appid,conf:conf})});
      }
    })();
    </script>
    <script type="text/javascript" src="https://assets.changyan.sohu.com/upload/plugins/plugins.count.js"></script>
  





  





  

  

  

  

  

  

</body>
</html>
